//
//  DiaryViewController.m
//  Diary
//
//  Created by 泉  姜 on 16/6/25.
//  Copyright © 2016年 泉  姜. All rights reserved.
//

#import "DiaryViewController.h"
#import "FirstCell.h"
#import "DiaryCell.h"

#define HEIGHT self.view.frame.size.height
#define WIDTH self.view.frame.size.width
@interface DiaryViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *picArr;
@property (nonatomic, strong)NSMutableArray *dateArr;

@end

@implementation DiaryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    
    [self backItem];
    
    [self createTableView];
}

- (void)backItem
{
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(left:)];
}

- (void)left:(UIBarButtonItem *)left
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createTableView
{
    self.picArr = [NSMutableArray array];
    self.dateArr = [NSMutableArray array];
    for (int i = 1; i < 11; i++) {
        NSString *pic = [NSString stringWithFormat:@"D%d", i];
        [_picArr addObject:[UIImage imageNamed:pic]];
    }
    
    self.dateArr = [NSMutableArray array];
    for (int i = 0; i < 10; i++) {
        _dateArr = [NSMutableArray arrayWithObjects:@"第十天  2016.06.15", @"第九天  2016.06.14", @"第八天  2016.06.13", @"第七天  2016.06.12", @"第六天  2016.06.11", @"第五天  2016.06.010", @"第四天  2016.06.09", @"第三天  2016.06.08", @"第二天  2016.06.07", @"第一天  2016.06.06", nil];
    }
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView registerClass:[FirstCell class] forCellReuseIdentifier:@"firstCell"];
    [_tableView registerClass:[DiaryCell class] forCellReuseIdentifier:@"cell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstCell" forIndexPath:indexPath];
        
        cell.timeImgView.image = [UIImage imageNamed:@"time"];
        [cell.timeLabel setText:[_dateArr objectAtIndex:indexPath.item]];
        [cell.diaryImgView setImage:[_picArr objectAtIndex:indexPath.item]];
        return cell;
    } else {
        DiaryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.timeImgView.image = [UIImage imageNamed:@"time"];
        [cell.timeLabel setText:[_dateArr objectAtIndex:indexPath.item]];
        [cell.diaryImgView setImage:[_picArr objectAtIndex:indexPath.item]];
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return HEIGHT * (260 / 667.0);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
